package com.isoft.teacher.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.isoft.teacher.mapper.teacherMapper;
import com.isoft.teacher.domain.teacher;
import com.isoft.teacher.service.IteacherService;

import javax.annotation.Resource;

/**
 * 教师管理Service业务层处理
 * 
 * @author lgm
 * @date 2024-07-16
 */
@Service
public class teacherServiceImpl implements IteacherService 
{
    @Autowired
//    @Resource
    private teacherMapper teacherMapper;

    /**
     * 查询教师管理
     * 
     * @param id 教师管理主键
     * @return 教师管理
     */
    @Override
    public teacher selectteacherById(Long id)
    {
        teacher teacher = teacherMapper.selectteacherById(id);
        teacher.setPassword(null);
        return teacher;
    }

    /**
     * 查询教师管理列表
     * 
     * @param teacher 教师管理
     * @return 教师管理
     */
    @Override
    public List<teacher> selectteacherList(teacher teacher)
    {
        List<teacher> teachers = teacherMapper.selectteacherList(teacher);
        for (teacher th : teachers) {
            th.setPassword(null);
        }
        return teachers;
    }

    /**
     * 新增教师管理
     * 
     * @param teacher 教师管理
     * @return 结果
     */
    @Override
    public int insertteacher(teacher teacher)
    {
//        密文存储
        teacher.setPassword(SecurityUtils.encryptPassword(teacher.getPassword()));
        return teacherMapper.insertteacher(teacher);
    }

    /**
     * 修改教师管理
     * 
     * @param teacher 教师管理
     * @return 结果
     */
    @Override
    public int updateteacher(teacher teacher)
    {
        teacher.setPassword(SecurityUtils.encryptPassword(teacher.getPassword()));
        return teacherMapper.updateteacher(teacher);
    }

    /**
     * 批量删除教师管理
     * 
     * @param ids 需要删除的教师管理主键
     * @return 结果
     */
    @Override
    public int deleteteacherByIds(Long[] ids)
    {
        return teacherMapper.deleteteacherByIds(ids);
    }

    /**
     * 删除教师管理信息
     * 
     * @param id 教师管理主键
     * @return 结果
     */
    @Override
    public int deleteteacherById(Long id)
    {
        return teacherMapper.deleteteacherById(id);
    }
}
